﻿@using  CompanyName.ProjectName.Web.Host.Model
@model DepartmentModel
@{
    Layout = "_LayoutForm";
    ViewData["title"] = "部门添加";
}

@section headers{

}

<form id="form1">

    @Html.HiddenFor(o => o.GoBackUrl)
    <div style="padding-top: 0px; margin-right: 30px;">

        <table class="form">
            <tr>
                <th class="formTitle">上级</th>
                <td class="formValue">

                    @Html.DropDownListFor(model => model.ParentId, Model.pids, new { @class = "form-control" })
                </td>
                <td></td>
                <th class="formTitle">名称</th>
                <td class="formValue">

                    @Html.TextBoxFor(model => model.Name, new { placeholder = "请输入名称", @class = "form-control" })
                </td>
                <td>

                    @Html.ValidationMessageFor(o => o.Name, null, new { @class = "help-inline" })
                </td>
            </tr>
            <tr>
                <th class="formTitle">部门代码</th>
                <td class="formValue">

                    @Html.TextBoxFor(model => model.Code, new { placeholder = "请输入部门代码", @class = "form-control" })
                </td>
                <td>

                    @Html.ValidationMessageFor(o => o.Code, null, new { @class = "help-inline" })
                </td>
                <th class="formTitle">负责人</th>
                <td class="formValue">

                    @Html.TextBoxFor(model => model.Manager, new { placeholder = "请输入负责人", @class = "form-control" })
                </td>

                <td></td>
            </tr>

            <tr>
                <th class="formTitle">联系电话</th>
                <td class="formValue">

                    @Html.TextBoxFor(model => model.ContactNumber, new { placeholder = "请输入联系电话", @class = "form-control" })
                </td>
                <td>
                </td>
                <th class="formTitle"></th>
                <td class="formValue">
                </td>

                <td></td>
            </tr>

            <tr>
                <th class="formTitle" valign="top" style="padding-top: 5px;">
                    备注
                </th>
                <td class="formValue" colspan="3">

                    @Html.TextAreaFor(o => o.Remarks, new { placeholder = "备注", @style = "height:100px;", @class = "form-control" })
                </td>
                <td colspan="2">
                    @Html.ValidationMessageFor(o => o.Remarks, null, new { @class = "help-inline" })
                </td>
            </tr>
        </table>

        <div class="clearfix form-actions">
            <label class="col-sm-3 control-label" for="form-field-1"> &nbsp; </label>
            <div class="col-md-9">
                <button class="btn btn-info" type="button" id="btnSave">
                    <i class="ace-icon fa fa-check bigger-110"></i>
                    确定
                </button>
                &nbsp;
                &nbsp;
                &nbsp;
                &nbsp;
                <a href="@Model.GoBackUrl" class="btn"><i class="ace-icon fa fa-arrow-left icon-on-left bigger-110"></i>返回</a>
            </div>
        </div>
    </div>
</form>

@section scripts{
    <script type="text/javascript">

          // 提交操作
          $("#btnSave").click(function (ev) {
              var $form = $("#form1");
              ////ev.preventDefault();

             if ($form.valid()) {
             //  if (true) {
                  //禁用提交按钮，避免重复提交
                  $.ajax({
                      url: "/Department/Create",
                      data: $form.serialize(),
                      type: "POST",
                      cache: false,
                      async: false,
                      beforeSend: function () {
                          $("#btnSave").attr("disabled", "disabled");
                      },
                      success: function (r) {

                          if (r.code == 0)
                          {
                              location.href = "@ViewBag.GoBackUrl";// "/Employee/index?ram=" + Math.random();// r.GoBackUrl;
                          }
                          else  // 其他问题
                          {
                              $.MsgBox.Alert(r.msg);
                          }
                          $("#btnSave").removeAttr("disabled");
                      },
                      error: function () {

                          $.MsgBox.Alert("保存失败");
                          $("#btnSave").removeAttr("disabled");
                      }
                  });

              }
              else {
                  //alert(5);
                  //移除禁止按钮。
                  $("#btnSave").removeAttr("disabled");

                }
          });
    </script>
}